//https://leetcode.cn/problems/symmetric-tree/description/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

bool checkisSymmetric(struct TreeNode* p, struct TreeNode* q)
{
    //左右子树两个都为空
    if (p == NULL && q == NULL)
    {
        return true;
    }

    //其中一个为空
    if (p == NULL || q == NULL)
    {
        return false;
    }

    //都不为空
    if (p->val != q->val)
    {
        return false;
    }

    return checkisSymmetric(p->left, q->right) && checkisSymmetric(p->right, q->left);

}

bool isSymmetric(struct TreeNode* root) {

    return checkisSymmetric(root, root);
}